* feat(release): publish package source, declaration maps, and documentation Every release member publishes its TypeScript source and the declaration maps that resolve into it, and @deepseek-ai/dsh publishes the repository Markdown documentation staged from docs/ at prepack time. The ./src/* export most members already declared now resolves for an installed consumer, and a consumer editor follows a declaration to the implementation. Bundled JavaScript maps stay unpublished; the vendored family and the Desktop runtime file policy are unchanged. Rationale: .agents/notes/implemented/process/2026-10-08-published-source-and-docs.md * feat(release): publish JavaScript maps and compress bundles Every emitted JavaScript map ships beside the bundle it describes, and the workspace build and the client preset compress bundles without mangling identifiers. The documentation payload now mirrors the website publication manifest and is removed again by `postpack`; Desktop and the Python executable exclude the published source, documentation, and maps; `clean` removes a staged copy. Typert's publication contract gains the Remote declaration map. * fix(release): keep node bundles readable for the worker image The browser worker image lowers `yield*` only as a whole statement and rewrites `for await` loops by their source layout, so compressed node-side entries either fail that lowering or lower to unparseable code. Only the browser bundles keep compression, which removes about a third of their text. The bundle-purity assertion now matches the module-loader call regardless of the quote style compression picks, and the release-pack fixture exercises the installed package's new documentation requirement. * feat(release): publish the whole documentation tree `@deepseek-ai/dsh` copies `docs/` in full instead of the website's page set: the maintainer documents, the generated migration records, the translation guidelines, and the `*.i18n.yaml` consistency records ship with the installed package, so the documentation's own links resolve without a checkout. * feat(release): publish the upgrade guides with the documentation The staged documentation keeps the website's page set and adds every `docs/upgrade-guide/` document, which is what an installed reader consults when a released change breaks something. The rest of the maintainer tree stays out. * test(release): expect source and maps in master's new payload cases * feat(release): keep installed docs and source readable in Desktop Desktop keeps the published src/ and docs/ trees inside app.asar, and every model shell call receives DSH_INSTALL_DIR and DSH_NODE_EXECUTABLE so an agent can read them through Electron's Node mode. Staging also generates docs/upgrade-guide/README.md, an index of the upgrade guides grouped by the release they upgrade from. Minified client bundles print string literals with backticks: the worker image packer now recognizes those chunk requests, client license banners are prepended after minification so their text survives, and the affected artifact tests accept either quote. * test(desktop): read archived docs through the Windows PowerShell form Regenerate the config catalog for the shifted shell-env source line. * test(desktop): wait for the GUI-subsystem Electron process from PowerShell * build(release): publish source and maps from the message-quotes package * build(release): publish source and maps from packages new on master * build(release): publish source and maps from the tool-office package
245 lines
9.8 KiB
TypeScript
245 lines
9.8 KiB
TypeScript
import { type Dirent } from 'node:fs'
|
|
import { lstat, readdir, realpath, rm } from 'node:fs/promises'
|
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import ts from 'typescript'
|
|
import { repositoryConfigHost } from './ts-project.ts'
|
|
|
|
const knownOrphanEntries = new Set(['node_modules', 'lib', '.typecheck'])
|
|
|
|
function errorCode(error: unknown): unknown {
|
|
return error instanceof Error && 'code' in error ? error.code : undefined
|
|
}
|
|
|
|
function isMissing(error: unknown): boolean {
|
|
return errorCode(error) === 'ENOENT'
|
|
}
|
|
|
|
async function exists(path: string): Promise<boolean> {
|
|
try {
|
|
await lstat(path)
|
|
return true
|
|
} catch (error) {
|
|
if (isMissing(error)) return false
|
|
throw error
|
|
}
|
|
}
|
|
|
|
async function directoryEntries(path: string): Promise<Dirent[]> {
|
|
try {
|
|
return await readdir(path, { withFileTypes: true })
|
|
} catch (error) {
|
|
if (isMissing(error)) return []
|
|
throw error
|
|
}
|
|
}
|
|
|
|
async function childDirectories(path: string): Promise<string[]> {
|
|
return (await directoryEntries(path)).filter(entry => entry.isDirectory()).map(entry => join(path, entry.name))
|
|
}
|
|
|
|
/** Lists symbolic links directly in a node_modules directory and in its `@scope` directories. */
|
|
async function moduleLinks(modulesDirectory: string): Promise<string[]> {
|
|
const links = (directory: string, entries: Dirent[]): string[] =>
|
|
entries.filter(entry => entry.isSymbolicLink()).map(entry => join(directory, entry.name))
|
|
const entries = await directoryEntries(modulesDirectory)
|
|
const result = links(modulesDirectory, entries)
|
|
for (const entry of entries) {
|
|
if (!entry.isDirectory() || !entry.name.startsWith('@')) continue
|
|
const scope = join(modulesDirectory, entry.name)
|
|
result.push(...links(scope, await directoryEntries(scope)))
|
|
}
|
|
return result
|
|
}
|
|
|
|
/** Resolves a link's canonical target, or undefined when the target cannot be reached. */
|
|
async function linkTarget(link: string): Promise<string | undefined> {
|
|
try {
|
|
return await realpath(link)
|
|
} catch (error) {
|
|
if (['ENOENT', 'ENOTDIR', 'ELOOP'].includes(String(errorCode(error)))) return undefined
|
|
throw error
|
|
}
|
|
}
|
|
|
|
function isDescendant(root: string, path: string): boolean {
|
|
const relativePath = relative(root, path)
|
|
return relativePath !== '' && relativePath !== '..' && !relativePath.startsWith(`..${sep}`) && !isAbsolute(relativePath)
|
|
}
|
|
|
|
function repositoryPath(root: string, path: string): string {
|
|
return relative(root, path).split(sep).join('/')
|
|
}
|
|
|
|
function parseConfig(configPath: string): ts.ParsedCommandLine {
|
|
const parsed = ts.getParsedCommandLineOfConfigFile(configPath, {}, repositoryConfigHost)
|
|
if (!parsed) throw new Error(`clean: cannot parse TypeScript config ${configPath}`)
|
|
if (parsed.errors.length > 0) {
|
|
throw new Error(parsed.errors.map(error => ts.flattenDiagnosticMessageText(error.messageText, '\n')).join('\n'))
|
|
}
|
|
return parsed
|
|
}
|
|
|
|
/** Plans and removes repository-owned build output without crossing the repository boundary. */
|
|
export class RepositoryCleaner {
|
|
private readonly root: string
|
|
|
|
constructor(root: string) {
|
|
this.root = resolve(root)
|
|
}
|
|
|
|
/**
|
|
* Remove generated build state and package directories containing only known residue.
|
|
* @returns Repository-relative paths that were removed.
|
|
*/
|
|
async clean(): Promise<string[]> {
|
|
const targets = await this.plan()
|
|
// Planning validates every target first, so an unsafe orphan prevents all deletion.
|
|
for (const target of targets) await rm(target, { recursive: true, force: true })
|
|
return targets.map(target => repositoryPath(this.root, target))
|
|
}
|
|
|
|
private async plan(): Promise<string[]> {
|
|
const targets = new Set<string>()
|
|
const unsafeOrphans: string[] = []
|
|
const canonicalRoot = await realpath(this.root)
|
|
|
|
await this.addIfPresent(targets, join(this.root, '.dsh-build'), canonicalRoot)
|
|
await this.addIfPresent(targets, join(this.root, 'apps/desktop/.desktop-build'), canonicalRoot)
|
|
// The CLI package's documentation copy: `prepack` writes it, `postpack` removes it.
|
|
await this.addIfPresent(targets, join(this.root, 'apps/cli/docs'), canonicalRoot)
|
|
|
|
// These checks cover legacy root-level incremental state emitted by older configs.
|
|
await this.addIfPresent(targets, join(this.root, '.typecheck'), canonicalRoot)
|
|
for (const entry of await readdir(this.root, { withFileTypes: true })) {
|
|
if (entry.isFile() && entry.name.endsWith('.tsbuildinfo')) targets.add(join(this.root, entry.name))
|
|
}
|
|
await this.addIfPresent(
|
|
targets,
|
|
join(this.root, 'native/system/tsconfig.tsbuildinfo'),
|
|
canonicalRoot,
|
|
)
|
|
|
|
// The root project-reference graph is the source of truth for live build targets.
|
|
// Each emitting project declares lib/types as outDir; its parent lib also owns
|
|
// the sibling runtime bundles, so the complete build output root is removed.
|
|
for (const outputDirectory of this.buildOutputDirectories()) {
|
|
await this.addIfPresent(targets, outputDirectory, canonicalRoot)
|
|
}
|
|
|
|
for (const groupDirectory of await childDirectories(join(this.root, 'packages'))) {
|
|
for (const packageDirectory of await childDirectories(groupDirectory)) {
|
|
// A package.json marks a live package; its output was discovered from the
|
|
// project graph above, and its package-local node_modules must be preserved.
|
|
if (await exists(join(packageDirectory, 'package.json'))) {
|
|
continue
|
|
}
|
|
|
|
// A manifest-less package directory is stale only when every remaining
|
|
// entry is known generated residue; unknown files make the whole clean fail.
|
|
const entries = await readdir(packageDirectory)
|
|
const unknown = entries.filter(entry => !knownOrphanEntries.has(entry) && !entry.endsWith('.tsbuildinfo'))
|
|
if (unknown.length > 0) {
|
|
unsafeOrphans.push(...unknown.map(entry => repositoryPath(this.root, join(packageDirectory, entry))))
|
|
} else {
|
|
await this.addIfPresent(targets, packageDirectory, canonicalRoot)
|
|
}
|
|
}
|
|
}
|
|
|
|
// pnpm install keeps links to deleted workspace packages. A link is residue when its
|
|
// target is unreachable or is removed by this plan; node_modules outside the repository is not scanned.
|
|
const removedPaths = (await Promise.all([...targets].map(linkTarget))).filter(path => path !== undefined)
|
|
for (const modulesDirectory of ['node_modules', 'node_modules/.pnpm/node_modules']) {
|
|
const canonicalModules = await linkTarget(join(this.root, modulesDirectory))
|
|
if (canonicalModules === undefined || !isDescendant(canonicalRoot, canonicalModules)) continue
|
|
for (const link of await moduleLinks(join(this.root, modulesDirectory))) {
|
|
const target = await linkTarget(link)
|
|
if (target === undefined || removedPaths.some(path => path === target || isDescendant(path, target))) {
|
|
await this.addIfPresent(targets, link, canonicalRoot)
|
|
}
|
|
}
|
|
}
|
|
|
|
if (unsafeOrphans.length > 0) {
|
|
throw new Error([
|
|
'clean: refusing to remove package directories without package.json; unknown entries remain:',
|
|
...unsafeOrphans.sort().map(path => ` ${path}`),
|
|
].join('\n'))
|
|
}
|
|
|
|
return [...targets].sort()
|
|
}
|
|
|
|
private buildOutputDirectories(): string[] {
|
|
const outputs = new Set<string>()
|
|
const pending = [join(this.root, 'tsconfig.json')]
|
|
const visited = new Set<string>()
|
|
const nativeEntryOutput = join(this.root, 'native/system/packages/entry/lib')
|
|
|
|
while (pending.length > 0) {
|
|
const nextConfigPath = pending.pop()
|
|
if (nextConfigPath === undefined) break
|
|
const configPath = resolve(nextConfigPath)
|
|
if (visited.has(configPath)) continue
|
|
visited.add(configPath)
|
|
|
|
const parsed = parseConfig(configPath)
|
|
if (parsed.options.outDir !== undefined) {
|
|
const typesDirectory = resolve(parsed.options.outDir)
|
|
const outputDirectory = basename(typesDirectory) === 'types'
|
|
? dirname(typesDirectory)
|
|
: typesDirectory === nativeEntryOutput
|
|
? typesDirectory
|
|
: undefined
|
|
if (outputDirectory === undefined) {
|
|
throw new Error(`clean: expected TypeScript outDir to end in /types: ${repositoryPath(this.root, typesDirectory)}`)
|
|
}
|
|
this.assertRepositoryTarget(outputDirectory)
|
|
outputs.add(outputDirectory)
|
|
}
|
|
|
|
for (const reference of parsed.projectReferences ?? []) {
|
|
pending.push(ts.resolveProjectReferencePath(reference))
|
|
}
|
|
}
|
|
|
|
return [...outputs]
|
|
}
|
|
|
|
private assertRepositoryTarget(path: string): void {
|
|
this.assertDescendant(this.root, path, path)
|
|
}
|
|
|
|
private assertDescendant(root: string, path: string, displayPath: string): void {
|
|
if (!isDescendant(root, path)) {
|
|
throw new Error(`clean: refusing deletion target outside repository: ${displayPath}`)
|
|
}
|
|
}
|
|
|
|
private async addIfPresent(targets: Set<string>, path: string, canonicalRoot: string): Promise<void> {
|
|
// Missing outputs are normal on a clean checkout; only existing paths become deletion targets.
|
|
if (!await exists(path)) return
|
|
// Resolve the parent rather than the final entry: rm unlinks a final symlink,
|
|
// but a symlink in an ancestor would make deletion cross the repository boundary.
|
|
const canonicalParent = await realpath(dirname(path))
|
|
this.assertDescendant(canonicalRoot, join(canonicalParent, basename(path)), path)
|
|
targets.add(path)
|
|
}
|
|
}
|
|
|
|
const scriptPath = fileURLToPath(import.meta.url)
|
|
if (process.argv[1] !== undefined && resolve(process.argv[1]) === scriptPath) {
|
|
try {
|
|
const removed = await new RepositoryCleaner(resolve(dirname(scriptPath), '..')).clean()
|
|
if (removed.length === 0) {
|
|
console.log('clean: already clean')
|
|
} else {
|
|
console.log(`clean: removed ${removed.length} paths`)
|
|
}
|
|
} catch (error) {
|
|
console.error(error instanceof Error ? error.message : error)
|
|
process.exitCode = 1
|
|
}
|
|
}
|