`src/index.ts` held the installer, the manager, the view fold, and every helper in one 1100-line file. It is now the package API alone, re-exporting from `installer.ts` (pnpm runs, the probe cache, post-install checks), `manager.ts` (every operation over the booted profile and the mutex), `view.ts` (the package view fold and the row-ownership walk the dependents query shares), `modules.ts` (declared-module row naming and views), and `helpers.ts` (the diagnostic prefix, tooling bounds, spawn seam, and manifest readers). The public surface, the tests, and the failure codes are unchanged.
52 lines
2.0 KiB
TypeScript
52 lines
2.0 KiB
TypeScript
/**
|
|
* The modules a package offers a composition: how a declared `dsh.plugins`
|
|
* entry is named as a row and derived into a row id, and its wire view.
|
|
* @module @deepseek-ai/dsh-plugin-manager/modules
|
|
*/
|
|
|
|
import type { PluginProbe } from '@deepseek-ai/dsh-app-boot'
|
|
import type { JsonValue } from '@deepseek-ai/dsh-util-values'
|
|
import { optional } from './helpers.ts'
|
|
import type { PluginPackageAddableView } from './types.ts'
|
|
|
|
/**
|
|
* The row `name` for one declared addable module.
|
|
* @param packageName - the package.
|
|
* @param declared - the `dsh.plugins[].name`, `.` for the main export.
|
|
* @returns the bare package for `.`, else `<package>/<subpath>`.
|
|
*/
|
|
export function moduleSpecifier(packageName: string, declared: string): string {
|
|
if (declared === '.') return packageName
|
|
return `${packageName}/${declared.replace(/^\.\//, '')}`
|
|
}
|
|
|
|
/**
|
|
* The row id derived from a package name and module: the unscoped name, then the subpath.
|
|
* @param packageName - the package.
|
|
* @param declared - the `dsh.plugins[].name`, `.` for the main export.
|
|
* @returns the row id.
|
|
*/
|
|
export function derivedRowId(packageName: string, declared: string): string {
|
|
const base = packageName.replace(/^@/, '')
|
|
return declared === '.' ? base : `${base}/${declared.replace(/^\.\//, '')}`
|
|
}
|
|
|
|
/**
|
|
* The wire view of one probed addable module.
|
|
* @param packageName - the package.
|
|
* @param entry - the probe's record of the declared module.
|
|
* @returns the view.
|
|
*/
|
|
export function addableView(packageName: string, entry: PluginProbe['addable'][number]): PluginPackageAddableView {
|
|
return {
|
|
moduleName: moduleSpecifier(packageName, entry.name),
|
|
declaredName: entry.name,
|
|
...optional('title', entry.title),
|
|
// The probe read both from JSON: a manifest field and a child's report.
|
|
...optional('config', entry.config as JsonValue | undefined),
|
|
ok: entry.ok,
|
|
...optional('error', entry.error),
|
|
...optional('configSchema', entry.configSchema as JsonValue | undefined),
|
|
}
|
|
}
|