Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/extension/remove.ts
6442 views
1
/*
2
* remove.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
import { basename, dirname } from "../deno_ral/path.ts";
7
import { removeIfEmptyDir } from "../core/path.ts";
8
import { kBuiltInExtOrg, kExtensionDir } from "./constants.ts";
9
import { Extension } from "./types.ts";
10
11
export async function removeExtension(extension: Extension) {
12
// You can't remove quarto extensions
13
if (extension.id.organization === kBuiltInExtOrg) {
14
throw new Error(
15
`The extension ${extension.title} can't be removed since it is a built in extension.`,
16
);
17
}
18
19
// Delete the extension
20
await Deno.remove(extension.path, { recursive: true });
21
22
// Remove the container directory, if empty
23
const extensionDir = dirname(extension.path);
24
removeIfEmptyDir(extensionDir);
25
26
// If the parent directory is an _extensions directory which is itself empty
27
// remove that too
28
const parentDir = dirname(extensionDir);
29
if (parentDir && basename(parentDir) === kExtensionDir) {
30
removeIfEmptyDir(parentDir);
31
}
32
}
33
34