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