Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/src/commands/extensions/uninstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { uninstallExtension } from '../../config/extension.js';
import { getErrorMessage } from '../../utils/errors.js';

interface UninstallArgs {
name: string;
name: string; // can be extension name or source URL.
}

export async function handleUninstall(args: UninstallArgs) {
Expand All @@ -28,7 +28,7 @@ export const uninstallCommand: CommandModule = {
builder: (yargs) =>
yargs
.positional('name', {
describe: 'The name of the extension to uninstall.',
Comment thread
hritan marked this conversation as resolved.
describe: 'The name or source path of the extension to uninstall.',
type: 'string',
})
.check((argv) => {
Expand Down
36 changes: 35 additions & 1 deletion packages/cli/src/config/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ describe('extension tests', () => {

it('should throw an error if the extension does not exist', async () => {
await expect(uninstallExtension('nonexistent-extension')).rejects.toThrow(
'Extension "nonexistent-extension" not found.',
'Extension not found.',
);
});

Expand All @@ -733,6 +733,40 @@ describe('extension tests', () => {
new ExtensionUninstallEvent('my-local-extension', 'success'),
);
});

it('should uninstall an extension by its source URL', async () => {
const gitUrl = 'https://github.com/google/gemini-sql-extension.git';
const sourceExtDir = createExtension({
extensionsDir: userExtensionsDir,
name: 'gemini-sql-extension',
version: '1.0.0',
installMetadata: {
source: gitUrl,
type: 'git',
},
});

await uninstallExtension(gitUrl);

expect(fs.existsSync(sourceExtDir)).toBe(false);
const logger = ClearcutLogger.getInstance({} as Config);
expect(logger?.logExtensionUninstallEvent).toHaveBeenCalledWith(
new ExtensionUninstallEvent('gemini-sql-extension', 'success'),
);
});

it('should fail to uninstall by URL if an extension has no install metadata', async () => {
createExtension({
extensionsDir: userExtensionsDir,
name: 'no-metadata-extension',
version: '1.0.0',
// No installMetadata provided
});

await expect(
uninstallExtension('https://github.com/google/no-metadata-extension'),
).rejects.toThrow('Extension not found.');
});
});

describe('performWorkspaceExtensionMigration', () => {
Expand Down
17 changes: 10 additions & 7 deletions packages/cli/src/config/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -573,17 +573,20 @@ export async function loadExtensionConfig(
}

export async function uninstallExtension(
extensionName: string,
extensionIdentifier: string,
cwd: string = process.cwd(),
): Promise<void> {
const logger = getClearcutLogger(cwd);
const installedExtensions = loadUserExtensions();
if (
!installedExtensions.some(
(installed) => installed.config.name === extensionName,
)
) {
throw new Error(`Extension "${extensionName}" not found.`);
const extensionName = installedExtensions.find(
(installed) =>
installed.config.name.toLowerCase() ===
extensionIdentifier.toLowerCase() ||
installed.installMetadata?.source.toLowerCase() ===
extensionIdentifier.toLowerCase(),
)?.config.name;
if (!extensionName) {
throw new Error(`Extension not found.`);
}
const manager = new ExtensionEnablementManager(
ExtensionStorage.getUserExtensionsDir(),
Expand Down
Loading