mirror of
https://ghproxy.cflmy.top/https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-12-02 18:11:37 +08:00
LibreOffice Kit 0.2.4 publishes its Linux engines as linux-x64-glibc and linux-arm64-glibc, but the sidecar and Desktop packaging looked for linux-<arch>, so a Linux target always fell back to WASM even when the kit declared a native engine. DSH's Linux distributions are glibc builds, so a Linux target now selects the glibc engine for its CPU. The third-party notices accept the two Linux engine packages under the same MPL-2.0 identity rule as the other engines. The web app and office-kit take Kit 0.2.4, the first release with those engines. Its release-age exclusions name the API and the six native engines; WASM is no longer an optional dependency of the kit and is no longer excluded. Because DSH no longer installs WASM, packaging now requires the target's declared native engine and rejects a target without one, naming its platform and CPU, instead of selecting a WASM package that cannot be present. The Python runtime smoke derives the same glibc package name and checks that the Office sidecar holds exactly that native engine. The Office provider, subsystem, package-surface and Desktop packaging documents describe Kit 0.2.4 and the native-only rule.
87 lines
4.3 KiB
JavaScript
87 lines
4.3 KiB
JavaScript
/** Locate the complete installed Office package closure used by standalone CLI processes. */
|
|
import { existsSync } from 'node:fs'
|
|
import { readFile } from 'node:fs/promises'
|
|
import { createRequire } from 'node:module'
|
|
import { isAbsolute, join, relative, sep } from 'node:path'
|
|
|
|
/**
|
|
* Require the declared native engine for the target. Linux distributions are glibc builds, so a Linux target selects
|
|
* the kit's glibc engine for its CPU.
|
|
* @param {{ optionalDependencies?: Record<string, string> }} manifest - Installed kit manifest.
|
|
* @param {{ platform: string, arch: string }} target - Distribution platform and CPU.
|
|
* @returns {string} Engine package suffix.
|
|
* @throws {Error} When the kit manifest does not declare a native engine for the target.
|
|
*/
|
|
export function selectOfficeEngine(manifest, target) {
|
|
const native = target.platform === 'linux' ? `linux-${target.arch}-glibc` : `${target.platform}-${target.arch}`
|
|
const name = `@deepseek-ai/libreoffice-kit-${native}`
|
|
if (!Object.hasOwn(manifest.optionalDependencies ?? {}, name)) {
|
|
throw new Error(`Office engine ${name} is not declared for ${target.platform}/${target.arch}.`)
|
|
}
|
|
return native
|
|
}
|
|
|
|
/**
|
|
* Find every required package, retaining its installed dependency resolution and target engine.
|
|
* @param {string} staging - Symlink-free installed Node project.
|
|
* @param {{ platform: string, arch: string }} target - Distribution platform and CPU.
|
|
* @returns {Promise<string[]>} Absolute package directories; rejects missing dependencies and paths outside staging.
|
|
*/
|
|
export async function officePackageDirectories(staging, target) {
|
|
const entry = join(staging, 'node_modules', '@deepseek-ai', 'libreoffice-kit')
|
|
const manifest = JSON.parse(await readFile(join(entry, 'package.json'), 'utf8'))
|
|
const engineName = `@deepseek-ai/libreoffice-kit-${selectOfficeEngine(manifest, target)}`
|
|
const packages = new Set()
|
|
|
|
/** @param {string} packageDirectory - Installed package directory. */
|
|
async function visit(packageDirectory) {
|
|
if (packages.has(packageDirectory)) return
|
|
const relativeDirectory = relative(staging, packageDirectory)
|
|
if (isAbsolute(relativeDirectory) || relativeDirectory === '..' || relativeDirectory.startsWith(`..${sep}`)) {
|
|
throw new Error(`Office dependency is outside the deployed closure: ${packageDirectory}`)
|
|
}
|
|
const manifestPath = join(packageDirectory, 'package.json')
|
|
const manifest = JSON.parse(await readFile(manifestPath, 'utf8'))
|
|
packages.add(packageDirectory)
|
|
const require = createRequire(manifestPath)
|
|
const dependencies = new Set([
|
|
...Object.keys(manifest.dependencies ?? {}),
|
|
...Object.keys(manifest.optionalDependencies ?? {}),
|
|
...Object.keys(manifest.peerDependencies ?? {}),
|
|
])
|
|
for (const name of dependencies) {
|
|
if (name.startsWith('@deepseek-ai/libreoffice-kit-')) continue
|
|
const optional = manifest.optionalDependencies?.[name] !== undefined
|
|
|| manifest.peerDependenciesMeta?.[name]?.optional === true
|
|
const dependencyDirectory = (require.resolve.paths(name) ?? [])
|
|
.map(directory => join(directory, name))
|
|
.find(directory => existsSync(directory))
|
|
if (dependencyDirectory === undefined) {
|
|
if (optional) continue
|
|
throw new Error(`Office dependency ${name} required by ${manifest.name} is missing.`)
|
|
}
|
|
if (optional) {
|
|
const dependency = JSON.parse(await readFile(join(dependencyDirectory, 'package.json'), 'utf8'))
|
|
if (!supports(dependency.os, target.platform) || !supports(dependency.cpu, target.arch)) continue
|
|
}
|
|
await visit(dependencyDirectory)
|
|
}
|
|
}
|
|
|
|
await visit(entry)
|
|
const engineDirectory = join(staging, 'node_modules', engineName)
|
|
if (!existsSync(engineDirectory)) throw new Error(`Office engine ${engineName} required for ${target.platform}/${target.arch} is missing.`)
|
|
await visit(engineDirectory)
|
|
return [...packages].sort()
|
|
}
|
|
|
|
/**
|
|
* @param {string[] | undefined} values - npm platform or CPU selectors.
|
|
* @param {string} value - Target platform or CPU.
|
|
* @returns {boolean} Whether the optional package supports the target.
|
|
*/
|
|
function supports(values, value) {
|
|
return values === undefined || (!values.includes(`!${value}`)
|
|
&& (values.every(item => item.startsWith('!')) || values.includes(value) || values.includes('any')))
|
|
}
|