Use profile-detection instead of rules-detection
This commit is contained in:
@@ -17,8 +17,8 @@ import { RULES_PROFILES } from '../../../../src/constants/profiles.js';
|
||||
import { RULES_ACTIONS } from '../../../../src/constants/rules-actions.js';
|
||||
import {
|
||||
wouldRemovalLeaveNoProfiles,
|
||||
getInstalledRulesProfiles
|
||||
} from '../../../../src/utils/rules-detection.js';
|
||||
getInstalledProfiles
|
||||
} from '../../../../src/utils/profile-detection.js';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
@@ -58,7 +58,7 @@ export async function rulesDirect(args, log, context = {}) {
|
||||
if (action === RULES_ACTIONS.REMOVE) {
|
||||
// Safety check: Ensure this won't remove all rules profiles (unless forced)
|
||||
if (!force && wouldRemovalLeaveNoProfiles(projectRoot, profiles)) {
|
||||
const installedProfiles = getInstalledRulesProfiles(projectRoot);
|
||||
const installedProfiles = getInstalledProfiles(projectRoot);
|
||||
const remainingProfiles = installedProfiles.filter(
|
||||
(profile) => !profiles.includes(profile)
|
||||
);
|
||||
|
||||
@@ -74,8 +74,8 @@ import {
|
||||
} from '../../src/ui/confirm.js';
|
||||
import {
|
||||
wouldRemovalLeaveNoProfiles,
|
||||
getInstalledRulesProfiles
|
||||
} from '../../src/utils/rules-detection.js';
|
||||
getInstalledProfiles
|
||||
} from '../../src/utils/profile-detection.js';
|
||||
|
||||
import { initializeProject } from '../init.js';
|
||||
import {
|
||||
@@ -2739,7 +2739,7 @@ Examples:
|
||||
if (!options.force) {
|
||||
// Check if this removal would leave no profiles remaining
|
||||
if (wouldRemovalLeaveNoProfiles(projectDir, expandedProfiles)) {
|
||||
const installedProfiles = getInstalledRulesProfiles(projectDir);
|
||||
const installedProfiles = getInstalledProfiles(projectDir);
|
||||
confirmed = await confirmRemoveAllRemainingProfiles(
|
||||
expandedProfiles,
|
||||
installedProfiles
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Rules Detection Utility
|
||||
* Helper functions to detect existing rules profiles in a project
|
||||
* Profile Detection Utility
|
||||
* Helper functions to detect existing profiles in a project
|
||||
*/
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -8,11 +8,11 @@ import { RULES_PROFILES } from '../constants/profiles.js';
|
||||
import { getRulesProfile } from './rule-transformer.js';
|
||||
|
||||
/**
|
||||
* Detect which rules profiles are currently installed in the project
|
||||
* Detect which profiles are currently installed in the project
|
||||
* @param {string} projectRoot - Project root directory
|
||||
* @returns {string[]} Array of installed profile names
|
||||
*/
|
||||
export function getInstalledRulesProfiles(projectRoot) {
|
||||
export function getInstalledProfiles(projectRoot) {
|
||||
const installedProfiles = [];
|
||||
|
||||
for (const profileName of RULES_PROFILES) {
|
||||
@@ -33,13 +33,13 @@ export function getInstalledRulesProfiles(projectRoot) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if removing the specified profiles would result in no rules profiles remaining
|
||||
* Check if removing the specified profiles would result in no profiles remaining
|
||||
* @param {string} projectRoot - Project root directory
|
||||
* @param {string[]} profilesToRemove - Array of profile names to remove
|
||||
* @returns {boolean} True if removal would result in no profiles remaining
|
||||
*/
|
||||
export function wouldRemovalLeaveNoProfiles(projectRoot, profilesToRemove) {
|
||||
const installedProfiles = getInstalledRulesProfiles(projectRoot);
|
||||
const installedProfiles = getInstalledProfiles(projectRoot);
|
||||
const remainingProfiles = installedProfiles.filter(
|
||||
(profile) => !profilesToRemove.includes(profile)
|
||||
);
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
getInstalledRulesProfiles,
|
||||
getInstalledProfiles,
|
||||
wouldRemovalLeaveNoProfiles
|
||||
} from '../../src/utils/rules-detection.js';
|
||||
} from '../../src/utils/profile-detection.js';
|
||||
import { rulesDirect } from '../../mcp-server/src/core/direct-functions/rules.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -33,7 +33,7 @@ describe('Rules Safety Check', () => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('getInstalledRulesProfiles', () => {
|
||||
describe('getInstalledProfiles', () => {
|
||||
it('should detect installed profiles correctly', () => {
|
||||
const projectRoot = '/test/project';
|
||||
|
||||
@@ -45,7 +45,7 @@ describe('Rules Safety Check', () => {
|
||||
return false;
|
||||
});
|
||||
|
||||
const installed = getInstalledRulesProfiles(projectRoot);
|
||||
const installed = getInstalledProfiles(projectRoot);
|
||||
expect(installed).toContain('cursor');
|
||||
expect(installed).toContain('roo');
|
||||
expect(installed).not.toContain('windsurf');
|
||||
@@ -58,7 +58,7 @@ describe('Rules Safety Check', () => {
|
||||
// Mock fs.existsSync to return false for all paths
|
||||
mockExistsSync.mockReturnValue(false);
|
||||
|
||||
const installed = getInstalledRulesProfiles(projectRoot);
|
||||
const installed = getInstalledProfiles(projectRoot);
|
||||
expect(installed).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user