Package the portable DSH profiles, local plugins, desktop integration, Firefox wrapper, and ownership-aware installer lifecycle. Bundle checksum-pinned OpenVSCode, editor extensions, translation assets, and cloudflared so unreliable upstream artifact downloads cannot break a clean installation.
52 lines
2.1 KiB
JavaScript
52 lines
2.1 KiB
JavaScript
import { readdir, readFile, writeFile } from 'node:fs/promises'
|
|
import { join } from 'node:path'
|
|
|
|
const homeDirectory = process.env.HOME
|
|
if (!homeDirectory) throw new Error('HOME is required.')
|
|
|
|
const profileDirectory = process.env.DSH_PROFILE_DIRECTORY || join(homeDirectory, '.dsh', 'profiles', 'web')
|
|
const extensionsDirectory = process.env.DSH_EDITOR_EXTENSIONS_DIRECTORY || join(homeDirectory, '.dsh', 'touched-git', 'editor', 'extensions')
|
|
|
|
async function replaceKnownText(filePath, oldText, newText) {
|
|
const content = await readFile(filePath, 'utf8')
|
|
if (content.includes(newText)) return false
|
|
if (!content.includes(oldText)) throw new Error(`Unsupported package contents: ${filePath}`)
|
|
await writeFile(filePath, content.replace(oldText, newText))
|
|
return true
|
|
}
|
|
|
|
async function exposeDiffViewer() {
|
|
const packageDirectory = join(profileDirectory, 'node_modules', '@dsh-external', 'dsh-diff-viewer')
|
|
await replaceKnownText(
|
|
join(packageDirectory, 'src', 'client', 'index.tsx'),
|
|
"import { MutationRow } from './mutation-row.tsx'",
|
|
"import { MutationRow } from './mutation-row.tsx'\nexport { DiffViewer } from './DiffViewer.tsx'\nexport type { DiffHunk, DiffViewerLabels, DiffViewMode } from './DiffViewer.tsx'",
|
|
)
|
|
await replaceKnownText(
|
|
join(packageDirectory, 'lib', 'client.js'),
|
|
'\t\texports.apply = apply;\n\t\texports.inject = inject;',
|
|
'\t\texports.DiffViewer = DiffViewer;\n\t\texports.apply = apply;\n\t\texports.inject = inject;',
|
|
)
|
|
}
|
|
|
|
async function patchLegacyBranchCompare() {
|
|
let entries
|
|
try {
|
|
entries = await readdir(extensionsDirectory, { withFileTypes: true })
|
|
} catch (error) {
|
|
if (error.code === 'ENOENT') return
|
|
throw error
|
|
}
|
|
|
|
for (const entry of entries) {
|
|
if (!entry.isDirectory() || !entry.name.startsWith('codexdebayan.branch-compare-')) continue
|
|
await replaceKnownText(
|
|
join(extensionsDirectory, entry.name, 'dist', 'git', 'GitService.js'),
|
|
"this.execGit(['diff', '--name-status', baseBranch, targetBranch])",
|
|
"this.execGit(['diff', '--name-status', baseBranch, targetBranch, '--'])",
|
|
)
|
|
}
|
|
}
|
|
|
|
await exposeDiffViewer()
|
|
await patchLegacyBranchCompare()
|