/** * Locate a dsh installation's dependency scope from a checkout. * * The plugin links harness packages into a bare checkout (see `dev-links.mjs`) * and `test/presets.test.js` reads the shipped `standard` preset to compare it * with this bundle's frozen copies. Both need the same answer to "where is the * harness?", so the search lives here rather than twice. * * There can be more than one answer. A harness home may carry the legacy * `profiles/node_modules` mirror that an older link backend projected, and that * mirror is a snapshot: packages added to the installation later are missing * from it. Callers that resolve more than one package should therefore try * every scope, not only {@link findHarnessScope}'s first answer. */ import { existsSync } from 'node:fs' import { join, resolve } from 'node:path' /** * Every dependency scope a dsh installation may occupy, newest layout first. * * @returns the directories that hold `@deepseek-ai/cordis`, deduplicated, in * preference order. */ export function harnessScopes() { const candidates = [ process.env.DSH_HARNESS_NODE_MODULES, resolve(process.env.DSH_HOME ?? join(process.env.HOME ?? '', '.dsh'), 'profiles', 'node_modules'), '/usr/local/lib/node_modules/@deepseek-ai/dsh/node_modules', ] const scopes = [] for (const candidate of candidates) { if (typeof candidate !== 'string' || !existsSync(join(candidate, '@deepseek-ai', 'cordis'))) continue if (!scopes.includes(candidate)) scopes.push(candidate) } return scopes } /** * The preferred dependency scope of a dsh installation. * * @returns the first directory that holds `@deepseek-ai/cordis`, or undefined. */ export function findHarnessScope() { return harnessScopes()[0] }