Clear dependencies correctly

This commit is contained in:
Misode
2024-11-21 05:16:59 +01:00
parent b535f55e76
commit 4bbff0969f

View File

@@ -10,7 +10,7 @@ import { useSpyglass, watchSpyglassUri } from '../../contexts/Spyglass.jsx'
import { AsyncCancel, useActiveTimeout, useAsync, useLocalStorage, useSearchParam } from '../../hooks/index.js'
import type { VersionId } from '../../services/index.js'
import { checkVersion, fetchDependencyMcdoc, fetchPreset, fetchRegistries, getSnippet, shareSnippet } from '../../services/index.js'
import { DEPENDENCY_URI } from '../../services/Spyglass.js'
import { DEPENDENCY_URI, SpyglassClient } from '../../services/Spyglass.js'
import { Store } from '../../Store.js'
import { cleanUrl, genPath } from '../../Utils.js'
import { Ad, Btn, BtnMenu, ErrorPanel, FileCreation, FileView, Footer, HasPreview, Octicon, PreviewPanel, ProjectPanel, SearchList, SourcePanel, TextInput, VersionSwitcher } from '../index.js'
@@ -96,6 +96,10 @@ export function SchemaGenerator({ gen, allowedVersions }: Props) {
if (!service || !uri) {
return AsyncCancel
}
const dependencies = await SpyglassClient.FS.readdir(DEPENDENCY_URI)
await Promise.all(dependencies.flatMap(async d => {
d.isFile() && d.name.startsWith(DEPENDENCY_URI) ? [await SpyglassClient.FS.unlink(d.name)] : []
}))
if (gen.dependency) {
const dependency = await fetchDependencyMcdoc(gen.dependency)
const dependencyUri = `${DEPENDENCY_URI}${gen.dependency}.mcdoc`